const express = require('express');
const router = express.Router();
const approvalController = require('../controllers/approvalController');

/**
 * @swagger
 * tags:
 *   name: Approval
 *   description: 审批管理接口
 */

/**
 * @swagger
 * /api/approval:
 *   post:
 *     summary: 创建新的审批记录
 *     tags: [Approval]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               type:
 *                 type: integer
 *                 description: 审批类型（1=采购审批，2=费用审批）
 *               name:
 *                 type: string
 *                 description: 审批名称
 *               initiator:
 *                 type: integer
 *                 description: 发起人ID
 *               current_approver:
 *                 type: array
 *                 items:
 *                   type: integer
 *                 description: 当前审批人ID集合
 *               approval_process:
 *                 type: object
 *                 description: 审批流程JSON
 *               approval_log:
 *                 type: array
 *                 description: 审批日志JSON
 *               approval_item:
 *                 type: integer
 *                 description: 审批项ID
 *               remark:
 *                 type: string
 *                 description: 备注信息
 *               attachment:
 *                 type: array
 *                 items:
 *                   type: string
 *                 description: 附件URL集合
 *     responses:
 *       200:
 *         description: 创建成功
 *       500:
 *         description: 服务器错误
 */
router.post('/api/approval', approvalController.createApproval);

/**
 * @swagger
 * /api/approval:
 *   get:
 *     summary: 获取所有审批记录
 *     tags: [Approval]
 *     responses:
 *       200:
 *         description: 返回审批列表
 *       500:
 *         description: 服务器错误
 */
router.get('/api/approval', approvalController.getAllApprovals);

/**
 * @swagger
 * /api/approval/{id}:
 *   get:
 *     summary: 根据ID获取审批详情
 *     tags: [Approval]
 *     parameters:
 *       - name: id
 *         in: path
 *         required: true
 *         schema:
 *           type: integer
 *         description: 审批ID
 *     responses:
 *       200:
 *         description: 返回审批详情
 *       404:
 *         description: 审批记录未找到
 *       500:
 *         description: 服务器错误
 */
router.get('/api/approval/:id', approvalController.getApprovalById);

/**
 * @swagger
 * /api/approval/{id}:
 *   put:
 *     summary: 更新审批记录
 *     tags: [Approval]
 *     parameters:
 *       - name: id
 *         in: path
 *         required: true
 *         schema:
 *           type: integer
 *         description: 审批ID
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             description: 要更新的审批数据
 *     responses:
 *       200:
 *         description: 更新成功
 *       404:
 *         description: 更新失败，记录不存在
 *       500:
 *         description: 服务器错误
 */
router.put('/api/approval/:id', approvalController.updateApproval);

/**
 * @swagger
 * /api/approval/{id}:
 *   delete:
 *     summary: 删除审批记录（软删除）
 *     tags: [Approval]
 *     parameters:
 *       - name: id
 *         in: path
 *         required: true
 *         schema:
 *           type: integer
 *         description: 审批ID
 *     responses:
 *       200:
 *         description: 删除成功
 *       404:
 *         description: 删除失败，记录不存在
 *       500:
 *         description: 服务器错误
 */
router.delete('/api/approval/:id', approvalController.deleteApproval);

module.exports = router;
